#include<bits/stdc++.h>
using namespace std;

// bool operator < (vector<int>& a, vector<int>& b)
// {
//     return ((a[1] != b[1]) ? a[1] < b[1] : a[0] < b[0]);
// }

bool cmp(vector<int>& a, vector<int>& b)
{
    return ((a[1] != b[1]) ? a[1] < b[1] : a[0] < b[0]);
}

class Solution {
public:
    int findLongestChain(vector<vector<int>>& pairs)
    {
        int n = pairs.size();
        int res = 1;
        int last = 0;
        sort(pairs.begin(), pairs.end(), cmp);
        for (int i = 1; i < pairs.size(); i++) {
            if (pairs[i][0] > pairs[last][1]) {
                res++;
                last = i;
            }
        }
        return res;
    }
};

/**
 * @date 2022-09-03
 * @brief 贪心
 */